package com.fengziyu.lib_recyclerview_fzy.net

import okhttp3.Interceptor
import okhttp3.Response

class TokenInterceptor(private val tokenProvider: ()-> String?): Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val token = tokenProvider.invoke()
        val newRequest = if(token != null){
            request.newBuilder()
                .addHeader("Token" , "token: $token")
                .build()
        }else{
            request
        }
        return chain.proceed(newRequest)
    }
}